Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Off diagonal #383

Merged
merged 16 commits into from
May 1, 2024
Merged

Off diagonal #383

merged 16 commits into from
May 1, 2024

Conversation

nquesada
Copy link
Collaborator

@nquesada nquesada commented Feb 15, 2024

A somewhat more numerically stable coherence calculation of the density matrix.

Copy link
Collaborator

@DavidSPhillips DavidSPhillips left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked through the changes and to me this all looks great, though I would be much happier if @rachelchadwick has a good look through too. Personally I'm happy to approve, pending the 1 failing test.

Copy link
Collaborator

@rachelchadwick rachelchadwick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice @nquesada ! I am still going through the finer details but I've left some comments/suggestions below. One general suggestion is to try to find a way of giving a warning when the recursive method is not correct. It would be nice to be able to use the recursive when it's correct and the non-recursive (ie slower) only when needed, but we have no easy way of knowing when it's working. Could we do some sanity checks like the diagonals are all >0 and <1 and the sum of them is getting closer to 1 as we increase cutoff? Not too sure how to check the off-diagonals. If you're happy with any suggestions but don't have time to implement them, let me know and I can always implement them.

@@ -17,6 +17,7 @@

import numpy as np
import numba
from scipy.special import factorial as fac
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just use the fact from .utils or is there something different?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it is just factorial from scipy.special

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why not use the stored factorials from utils to avoid recalculating like we do in _density_matrix_single_mode?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, good point.

thewalrus/internal_modes/fock_density_matrices.py Outdated Show resolved Hide resolved
thewalrus/internal_modes/fock_density_matrices.py Outdated Show resolved Hide resolved
thewalrus/internal_modes/pnr_statistics.py Outdated Show resolved Hide resolved
thewalrus/tests/test_internal_modes.py Outdated Show resolved Hide resolved
thewalrus/tests/test_internal_modes.py Outdated Show resolved Hide resolved
nquesada and others added 4 commits April 23, 2024 12:47
* Minor fixes

* passes black

* Fix test

* removes unused function

* test error is raised

* test error is raised

* Passes black

* Passes black

---------

Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>
Co-authored-by: rachelchadwick <33873960+rachelchadwick@users.noreply.github.com>
* Now the non-recursive function do not produce warning

* Now the non-recursive function do not produce warning

* Passes black

* Simplifies the diagonal method

* More tests, always

* More tests, always

* minor pylint improvements

* Adds extra test

* black

* minor simplification

* some tests pass

* some tests pass

* Moves the tests that take forever to the end of the test file

* Passes black

* Adds else

---------

Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>
* Adds the warning

* passes black

* Apply suggestions from code review

Co-authored-by: rachelchadwick <33873960+rachelchadwick@users.noreply.github.com>

* Update thewalrus/internal_modes/fock_density_matrices.py

---------

Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>
Co-authored-by: rachelchadwick <33873960+rachelchadwick@users.noreply.github.com>
* Fix numba types

* Passes black

* Apply suggestions from code review

* Apply suggestions from code review

* passes black

* Make lists tuples

* Check non-recursive

* Tests with high tolerances

* Run black

* Update test_density_matrix

* Minor changes

---------

Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>
Co-authored-by: Nicolas Quesada <991946+nquesada@users.noreply.github.com>
nquesada and others added 3 commits April 26, 2024 16:32
Co-authored-by: rachelchadwick <33873960+rachelchadwick@users.noreply.github.com>
commit 7c63905
Merge: 127a1a7 f935053
Author: Eli Bourassa <53090166+elib20@users.noreply.github.com>
Date:   Mon Apr 29 14:16:22 2024 -0400

    Merge branch 'master' into internal_modes

commit f935053
Author: Alberto Fumagalli <alberto@xanadu.ai>
Date:   Mon Apr 29 14:14:51 2024 -0400

    Add codecov token to test workflow (#390)

commit fe9e112
Author: Nicolas Quesada <991946+nquesada@users.noreply.github.com>
Date:   Wed Apr 10 15:31:34 2024 -0400

    Updates references (#384)

    * updates references

    * Updates biblio

    ---------

    Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>

commit 25b5f08
Author: Nicolas Quesada <991946+nquesada@users.noreply.github.com>
Date:   Wed Feb 28 20:35:28 2024 -0500

    Implements the pre-Iwasawa and Iwasawa decompositions. (#382)

    * First working version

    * First working version

    * First working version

    * better tests

    * better tests

    * Finally correct

    * Finally correct

    * putting the traingles in the right places

    * Removes unnecesary T

    * More tests

    * More tests and spell correction

    * More tests and spell correction

    * Removes unnecesary complex number usage

    * Apply suggestions from code review

    Co-authored-by: Sebastián Duque Mesa <675763+sduquemesa@users.noreply.github.com>

    * Apply suggestions from code review

    Co-authored-by: Sebastián Duque Mesa <675763+sduquemesa@users.noreply.github.com>

    ---------

    Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>
    Co-authored-by: Sebastián Duque Mesa <675763+sduquemesa@users.noreply.github.com>

commit 127a1a7
Merge: e6de063 8759363
Author: Nicolas Quesada <991946+nquesada@users.noreply.github.com>
Date:   Tue Feb 13 16:43:20 2024 -0500

    Merge branch 'master' into internal_modes

commit 8759363
Author: Nicolas Quesada <991946+nquesada@users.noreply.github.com>
Date:   Thu Feb 1 16:57:23 2024 -0500

    Better blochmessiah (#381)

    * Nicer BM

    * Updates changelog

    * Unnecesary import

    * More simplifications

    * More simplifications

    * one more

    * Updates docstring

    ---------

    Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>

commit 6247fc8
Author: Nicolas Quesada <991946+nquesada@users.noreply.github.com>
Date:   Wed Jan 24 10:43:57 2024 -0500

    Updates docstring and simplifies Williamson (#380)

    Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>

commit 0b1af63
Author: Sebastián Duque Mesa <675763+sduquemesa@users.noreply.github.com>
Date:   Thu Jan 11 17:09:32 2024 -0500

    Increment version number to `0.22.0-dev` (#379)

commit 544c457
Author: Sebastián Duque Mesa <675763+sduquemesa@users.noreply.github.com>
Date:   Wed Jan 10 16:52:38 2024 -0500

    bump version to `0.21.0` (#378)

commit 2268bf0
Author: Nicolas Quesada <991946+nquesada@users.noreply.github.com>
Date:   Thu Jan 4 11:12:27 2024 -0500

    Adds extra degenerate tests with nonvac nullspace (#377)

    * Adds extra degenerate tests with nonvac nullspace

    * updates changelog

    * updates changelog

    * updates changelog

    * Removes unnecesary comment

    * Still breaking something

    * Simplifications still work

    * Simplifications still work

    * Fixes bug

    ---------

    Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>

commit 8ec2172
Author: Nicolas Quesada <991946+nquesada@users.noreply.github.com>
Date:   Wed Nov 29 15:53:11 2023 -0500

    Implements the Montrealer (#374)

    * Saving changes

    * Passes black

    * Passes black

    * Black

    * updates acknowledgements and changelog

    * updates acknowledgements and changelog

    * Adds montrealer

    * Adds Montrealer tests (#375)

    * Yanic the pirate

    * mtl test

    * mtl first tests

    * mtl test

    * test mtl

    * test montrealer

    * test montrealer

    * test Montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * tests montrealer

    * montrealer test

    * montrealer test

    * montrealer test

    * montrealer test

    * montrealer test

    * test montrealer

    * test montrealer

    * montrealer test

    * montrealer test

    * montrealer test

    * montrealer tests

    * montrealer tests

    * montrealer tests

    * montrealer tests

    * functions header update

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer ready for review

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer - failed tests

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * test montrealer

    * the rspms are now ordered

    * Passes black

    * garbage test file to be deleted later

    * minor changes

    * Done

    ---------

    Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>

    * making bots happy

    * Apply suggestions from code review

    Co-authored-by: Sebastián Duque Mesa <675763+sduquemesa@users.noreply.github.com>

    * Apply suggestions from code review

    Co-authored-by: Sebastián Duque Mesa <675763+sduquemesa@users.noreply.github.com>

    * Apply suggestions from code review

    * Apply suggestions from code review

    Co-authored-by: Sebastián Duque Mesa <675763+sduquemesa@users.noreply.github.com>

    * Apply suggestions from code review

    Co-authored-by: Sebastián Duque Mesa <675763+sduquemesa@users.noreply.github.com>

    * Adds extra tests

    ---------

    Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>
    Co-authored-by: Yanic Cardin <yanic.cardin.1@gmail.com>
    Co-authored-by: Sebastián Duque Mesa <675763+sduquemesa@users.noreply.github.com>

commit 0e163bf
Author: Nicolas Quesada <991946+nquesada@users.noreply.github.com>
Date:   Tue Aug 22 10:19:08 2023 -0400

    Update symplectic.py (#372)

    * Update decompositions.py

    * New takagi

    * New takagi

    * Passes black

    * Simplifies blochmessiah

    * Simplifies blochmessiah

    * Found a case that breaks Takagi

    * Fixes all the tests

    * Fixes issues found by the linter

    * Adds extra test

    * Adds extra test

    * dummy

    * dummy

    * Update symplectic.py

    Removes `autonne`

    * relocates test

    * trying to make pylint happy

    ---------

    Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>

commit e999e49
Author: Nicolas Quesada <991946+nquesada@users.noreply.github.com>
Date:   Thu Aug 17 12:55:45 2023 -0400

    Better way to determine if a matrix is a phase times a real matrix (#373)

    * Add a better way to determine if a matrix is a phase times a real matrix and tests

    * CHANGELOG updates

    ---------

    Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>
Copy link

codecov bot commented Apr 30, 2024

Codecov Report

Attention: Patch coverage is 98.36066% with 1 lines in your changes are missing coverage. Please review.

❗ No coverage uploaded for pull request base (internal_modes@7c63905). Click here to learn what that means.

Additional details and impacted files
@@                Coverage Diff                @@
##             internal_modes     #383   +/-   ##
=================================================
  Coverage                  ?   99.95%           
=================================================
  Files                     ?       33           
  Lines                     ?     2227           
  Branches                  ?        0           
=================================================
  Hits                      ?     2226           
  Misses                    ?        1           
  Partials                  ?        0           
Files Coverage Δ
thewalrus/_hafnian.py 100.00% <ø> (ø)
thewalrus/internal_modes/__init__.py 100.00% <100.00%> (ø)
thewalrus/internal_modes/pnr_statistics.py 100.00% <100.00%> (ø)
thewalrus/internal_modes/utils.py 100.00% <ø> (ø)
thewalrus/internal_modes/fock_density_matrices.py 98.57% <98.24%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7c63905...621e982. Read the comment docs.

@nquesada
Copy link
Collaborator Author

@rachelchadwick this worked!
Looking fwd to see this branch merged!

@rachelchadwick
Copy link
Collaborator

@rachelchadwick this worked! Looking fwd to see this branch merged!

@nquesada But it seems to fail with a segmentation fault most of the time. That's not something I want to merge into main for sure.

@rachelchadwick
Copy link
Collaborator

Ok I've run it several times now with no problem so the segmentation error seems to have fixed itself too. So unless there are any objections I'll merge this one into internal_modes tomorrow.

@rachelchadwick rachelchadwick merged commit c390f84 into internal_modes May 1, 2024
4 checks passed
@rachelchadwick rachelchadwick deleted the off_diagonal branch May 1, 2024 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants